
package com.ffcs.crmd.tsp.admin.facade.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ctg.itrdc.platform.common.entity.PageInfo;
import com.ctg.itrdc.platform.common.utils.bean.BeanUtils;
import com.ffcs.crmd.platform.core.ddd.facade.impl.AbstractCrmDomFacade;
import com.ffcs.crmd.tsp.admin.api.dto.JobGroupDTO;
import com.ffcs.crmd.tsp.admin.api.facade.IJobGroupFacade;
import com.ffcs.crmd.tsp.admin.entity.JobGroup;
import com.ffcs.crmd.tsp.admin.service.IJobGroupService;

@Service("jobGroupFacade")
public class JobGroupFacadeImpl extends AbstractCrmDomFacade implements IJobGroupFacade {
    
    @Autowired
    private IJobGroupService jobGroupService;
    
    private PageInfo<JobGroupDTO> copyPageInfo(PageInfo<JobGroup> pageInfo) throws Exception {
        PageInfo<JobGroupDTO> pageInfoDto = new PageInfo<JobGroupDTO>();
        BeanUtils.applyIf(pageInfoDto, pageInfo, false);
        pageInfoDto.setList(BeanUtils.copyList(pageInfo.getList(), JobGroupDTO.class));
        return pageInfoDto;
    }
    
    @Override
    public JobGroupDTO get(JobGroupDTO jobGroupDto) throws Exception {
        JobGroup jobGroup = new JobGroup();
        BeanUtils.applyIf(jobGroup, jobGroupDto, false);
        
        JobGroup rjobGroup = jobGroupService.get(jobGroup);
        JobGroupDTO rjobGroupDTO = new JobGroupDTO();
        BeanUtils.applyIf(rjobGroupDTO, rjobGroup, false);
        return rjobGroupDTO;
    }
    
    @Override
    public void pause(List<JobGroupDTO> jobGroupDTOList) throws Exception {
        List<JobGroup> jobGroupList = BeanUtils.copyList(jobGroupDTOList, JobGroup.class);
        jobGroupService.pause(jobGroupList);
    }
    
    @Override
    public List<JobGroupDTO> query(JobGroupDTO jobGroupDto) throws Exception {
        JobGroup jobGroup = new JobGroup();
        BeanUtils.applyIf(jobGroup, jobGroupDto, false);
        
        List<JobGroup> jobGroupList = jobGroupService.query(jobGroup);
        return BeanUtils.copyList(jobGroupList, JobGroupDTO.class);
    }
    
    @Override
    public PageInfo<JobGroupDTO> queryPage(JobGroupDTO jobGroupDto) throws Exception {
        JobGroup jobGroup = new JobGroup();
        BeanUtils.applyIf(jobGroup, jobGroupDto, false);
        
        PageInfo<JobGroup> pageInfo = jobGroupService.queryPage(jobGroup, jobGroupDto.getPageNumber(), jobGroupDto.getPageSize());
        return copyPageInfo(pageInfo);
    }
    
    
    @Override
    public void remove(JobGroupDTO jobGroupDto) throws Exception {
        JobGroup jobGroup = new JobGroup();
        BeanUtils.applyIf(jobGroup, jobGroupDto, false);
        jobGroupService.deleteJobGroup(jobGroup);
    }
    
    @Override
    public void remove(List<JobGroupDTO> jobGroupDtoList) throws Exception {
        List<JobGroup> jobGroupList = BeanUtils.copyList(jobGroupDtoList, JobGroup.class);
        jobGroupService.deleteJobGroup(jobGroupList);
    }
    
    @Override
    public void resume(List<JobGroupDTO> jobGroupDTOList) throws Exception {
        List<JobGroup> jobGroupList = BeanUtils.copyList(jobGroupDTOList, JobGroup.class);
        jobGroupService.resume(jobGroupList);
    }
    
    @Override
    public void save(JobGroupDTO jobGroupDto) throws Exception {
        JobGroup jobGroup = new JobGroup();
        BeanUtils.applyIf(jobGroup, jobGroupDto, false);
        jobGroupService.saveJobGroup(jobGroup);
    }
    
    @Override
    public void update(JobGroupDTO jobGroupDto) throws Exception {
        JobGroup jobGroup = new JobGroup();
        BeanUtils.applyIf(jobGroup, jobGroupDto, false);
        jobGroupService.updateJobGroup(jobGroup);
    }
}
